﻿CREATE PROCEDURE [dbo].[proc_CheckInOut_GetEmployeeList_new]
(
	@StartIndex int,
	@EndIndex INT,
	@UserName nvarchar(50),
	@SearchTxt nvarchar(100)
)
AS
	;WITH List As(Select ROW_NUMBER() OVER (Order By CheckOutTime Desc) AS Row,
		Id,
		CompanyId,
		CustomerId,
		(select CustomerName from Customer where CheckInOut.CustomerId = Customer.CustomerId) as CustomerName,
		ContactPerson,
		ContactTel, 
		Address,
		MainProjectId,
		(Select Title From Product Where Id=CheckInOut.MainProjectId) As MainProject,
		Content,
		UserName,
		CheckOutTime,
		ISNULL(CheckInTime,'')AS CheckInTime,
		PositionTime,PositionAddress	
		From CheckInOut
	             WHERE UserName=@UserName
				 and (select CustomerName from Customer where CheckInOut.CustomerId = Customer.CustomerId) like '%'+@SearchTxt+'%'
	)
	Select *,(Select Count(0) From list) As RecordCount From list Where Row Between @StartIndex and @EndIndex Order By Row
